#include "EPSGLua/Global.h"

#include "lua.hpp"

EPSGLua::Global* EPSGLua::Global::s_instance = NULL;
lua_State* EPSGLua::Global::s_luaState = NULL;

EPSGLua::Global::Global()
{
	s_luaState = lua_open();
	luabind::open( s_luaState );
	luaopen_base( s_luaState );
	luaopen_math( s_luaState );
	luaopen_os( s_luaState );
	luaL_dostring( s_luaState, "collectgarbage( 'stop' )" );
}

EPSGLua::Global::~Global()
{
	lua_close( s_luaState );
}

EPSGLua::Global* EPSGLua::Global::instance()
{
	if( s_instance == NULL )
		s_instance = new Global();

	return s_instance;
}

lua_State* EPSGLua::Global::getLuaState()
{
	return s_luaState;
}